/**
 * 
 */
package deathKitten;

/**
 * @author Adam
 *
 *This class combines SHA512 hashes into either a 512 or 1024 bit hash to feed the key scheduler
 *
 *This entire class needs to be cleaned up and validated.  
 *
 *it should work but needs to be done right
 *
 */
public class KeyMaker {
	public byte[] keyMaker (byte[] passwordHash, byte[] keyFileHash1, byte[] keyFileHash2, byte[] keyFileHash3){
		
		byte[] output = null;
		
		if (passwordHash == null){
			output = null;
		}
		else if (((keyFileHash1 == null)&&(keyFileHash2 == null) && (keyFileHash3 == null)) && (passwordHash != null)){
			output = passwordHash;
		}
		else if (((keyFileHash2 == null)&&(keyFileHash3 == null))&&((passwordHash != null) && (keyFileHash1 != null))){
			output = concat(passwordHash, keyFileHash1);
		}
		else if ((keyFileHash3 == null)&&(passwordHash != null) && (keyFileHash1 != null)&&(keyFileHash2 != null)){
			output = (concat((xor(passwordHash, keyFileHash2)),(xor(keyFileHash1, keyFileHash2))));
		}
		else if ((keyFileHash3 != null)&&(passwordHash != null) && (keyFileHash1 != null)&&(keyFileHash2 != null)){
			output = (concat((xor(passwordHash, keyFileHash2)),(xor(keyFileHash1, keyFileHash3))));
		}
		return output;
	}
	
	private byte[] concat(byte[] A, byte[] B) {
		   byte[] C= new byte[A.length+B.length];
		   System.arraycopy(A, 0, C, 0, A.length);
		   System.arraycopy(B, 0, C, A.length, B.length);

		   return C;
		}
	
	private byte[] xor (byte[] A, byte[] B){
		
		byte[] e = new byte[A.length];
		for ( int i=0; i<A.length; i++ )
		   {
		   e[i] = (byte)( A[i] ^ B[i] );
		   }
		return e;
	}

}
